#include <maya/MFnPlugin.h>
#include <maya/MGlobal.h>

#include "source/xsCustomSkinCmd.h"
#include "source/customSkinDeformer.h"
#include "source/skinPainterContextCmd.h"


#pragma comment(lib, "Foundation.lib")
#pragma comment(lib, "OpenMaya.lib")
#pragma comment(lib, "OpenMayaAnim.lib")
#pragma comment(lib, "OpenMayaRender.lib")
#pragma comment(lib, "OpenMayaUI.lib")
#pragma comment(lib, "Qt5Core.lib")
#pragma comment(lib, "Qt5Gui.lib")


MStatus initializePlugin(MObject obj)
{
	MStatus result;
	const char* vendor = "XuShi";
	const char* version = "1.0.0";
	
	MFnPlugin plugin(obj, vendor, version);

	// cmd
	result = plugin.registerCommand(xsCustomSkinCmd::cmdName, &xsCustomSkinCmd::creator, &xsCustomSkinCmd::createSyntax);
	if (result == MStatus::kFailure)
	{
		MGlobal::displayError("Command: " + xsCustomSkinCmd::cmdName + " register failed");
		return result;
	}
	
	// deformer
	result = plugin.registerNode(customSkinDeformer::nodeName, customSkinDeformer::id, &customSkinDeformer::creator,
								&customSkinDeformer::initialize, MPxNode::kDeformerNode);
	if (result == MStatus::kFailure)
	{
		MGlobal::displayError("Deformer: " + customSkinDeformer::nodeName + " register failed");
		return result;
	}

	// context cmd
	result = plugin.registerContextCommand(skinPainterContextCmd::cmdName, &skinPainterContextCmd::creator);
	if (result == MStatus::kFailure)
	{
		MGlobal::displayError("Context: " + skinPainterContextCmd::cmdName + " register failed");
		return result;
	}

	return MStatus::kSuccess;
}

MStatus uninitializePlugin(MObject obj)
{
	MStatus result;
	MFnPlugin plugin(obj);
	
	// cmd
	result = plugin.deregisterCommand(xsCustomSkinCmd::cmdName);
	if (result == MStatus::kFailure)
	{
		MGlobal::displayError("Command: " + xsCustomSkinCmd::cmdName + " deregister failed");
		return result;
	}
	
	// deformer
	result = plugin.deregisterNode(customSkinDeformer::id);
	if (result == MStatus::kFailure)
	{
		MGlobal::displayError("Deformer: " + customSkinDeformer::nodeName + " deregister failed");
		return result;
	}

	// context cmd
	result = plugin.deregisterContextCommand(skinPainterContextCmd::cmdName);
	if (result == MStatus::kFailure)
	{
		MGlobal::displayError("Context: " + skinPainterContextCmd::cmdName + " deregister failed");
		return result;
	}

	return MStatus::kSuccess;
}
